<template>
  <!-- 我的审批 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth-button="['add/contractManagement']"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-select
            v-model="searchValue.type"
            placeholder="请选择流程类型"
            style="width: 100%"
            clearable
          >
            <el-option
              v-for="item in streamTypeList"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            />
          </el-select>
          <el-select
            v-model="searchValue.status"
            placeholder="请选择状态"
            style="width: 100%"
            clearable
          >
            <el-option label="待审核" :value="0" />
            <el-option label="已通过" :value="1" />
            <el-option label="未通过" :value="2" />
            <!-- <el-option label="审核中" :value="3" /> -->
            <!-- <el-option label="作废" :value="4" /> -->
          </el-select>

          <el-date-picker
            v-model="searchValue.startTime"
            value-format="YYYY-MM-DD"
            type="date"
            placeholder="开始时间"
            :teleported="false"
            style="width: 100%"
          ></el-date-picker>
          <el-date-picker
            v-model="searchValue.endTime"
            value-format="YYYY-MM-DD"
            type="date"
            placeholder="结束时间"
            :teleported="false"
            style="width: 100%"
          ></el-date-picker>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        stripe
        @filterType="filterType"
        @row-dblclick="handleRowClick"
      >
        <el-table-column
          label="ID"
          prop="id"
          width="80"
          fixed
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="主题"
          prop="title"
          min-width="150"
          fixed
        ></el-table-column>
        <el-table-column label="类型" prop="examineType" width="200" fixed>
          <template #default="scope">
            <!-- 0表单审核 1申请修改 -->
            <p>{{ scope.row.examineType == 0 ? "表单审核" : "申请修改" }}</p>
          </template>
        </el-table-column>
        <el-table-column label="摘要" prop="detail" min-width="200" fixed>
          <template #default="scope">
            <item-detail
              ref="itemDetail"
              :data="scope.row.detail"
            ></item-detail>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="totalStatus" width="300">
          <template #default="scope">
            <!-- 0未审核 1审核通过 2审核拒绝  -->
            <el-tag
              type="warning"
              v-if="scope.row.status == 0 && scope.row.examineStatus == 0"
            >
              待审核
            </el-tag>
            <el-tag
              type="success"
              v-if="scope.row.status == 1 || scope.row.examineStatus == 1"
            >
              通 过
            </el-tag>
            <el-tag
              type="danger"
              v-if="scope.row.status == 2 || scope.row.examineStatus == 2"
            >
              未通过
            </el-tag>
            <!-- <el-tag
              type="warning"
              v-if="scope.row.status == 3 && scope.row.examineStatus == 3"
            >
              审核中
            </el-tag> -->
          </template>
        </el-table-column>
        <el-table-column
          label="申请时间"
          prop="createTime"
          width="300"
        ></el-table-column>
        <el-table-column
          label="申请人"
          prop="applicantName"
          width="300"
        ></el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_check(scope.row, scope.$index)"
                v-if="
                  scope.row.status == 0 &&
                  scope.row.examineStatus == 0 &&
                  scope.row.examinePreStatus == 1
                "
                >审核</el-button
              >
              <el-button
                text
                type="success"
                size="small"
                @click="table_addSgin(scope.row, scope.$index)"
                v-if="
                  scope.row.status == 0 &&
                  scope.row.isAddSign == 1 &&
                  scope.row.examineStatus == 0
                "
                >加签</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
    <check-dialog ref="checkDialog" @update="update"></check-dialog>
    <add-sgin-dialog ref="addSginDialog" @update="update"></add-sgin-dialog>
  </el-container>
</template>
<script>
import itemDetail from '../components/itemDetail.vue'
import checkDialog from '@/components/checkDialog'
import { queryTypeByDic } from '@/utils/getData'
import { handleClick, initTableRow } from '@/utils/handleRouter'
import addSginDialog from '@/components/addSign'
export default {
  name: 'myExamine',
  data () {
    return {
      apiObj: this.$API.home.getMyExamineList,
      produceStatus: [],//生产单状态
      deliverStatus: [],//送货状态
      followType: [],//跟进类型
      searchValue: {
        type: null,//流程类型
        endTime: null,
        startTime: null,
        status: null//状态
      },
      streamTypeList: []//流程类型列表
    }
  },
  components: {
    itemDetail,
    checkDialog,
    addSginDialog
  },
  mounted () {
    this.getType()
  },
  methods: {
    table_check (row) {
      console.log(row)
      this.$nextTick(() => {
        this.$refs.checkDialog.open(row)
      })
    },
    async getType () {
      this.produceStatus = await queryTypeByDic('produceStatus')
      this.deliverStatus = await queryTypeByDic('deliverStatus')
      this.followType = await queryTypeByDic('followType')
      this.streamTypeList = await queryTypeByDic('streamCode')
    },
    //加签
    table_addSgin (row) {
      let data = {
        correlationId: row.correlationId,
        streamType: row.streamType,
        examineUserId: row.examineUserId,
        auditType: row.auditType,
        isAddSign: row.isAddSign,
      }
      this.$nextTick(() => {
        this.$refs.addSginDialog.open(data)
      })
    },

    filterType (data) {
      initTableRow(data)
    },

    handleRowClick (row) {
      handleClick(row.streamType, row.detail.id)
    },
    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },
    update () {
      this.$refs.table.refresh()
    }
  }
}
</script>

<style>
</style>